package com.yuwubao.hz_International.quartz

import com.yuwubao.hz_International.entities.WelfareTotal
import com.yuwubao.hz_International.services.AppService
import com.yuwubao.hz_International.services.impl.retain
import org.springframework.scheduling.annotation.Scheduled
import org.springframework.stereotype.Component
import java.math.BigDecimal
import java.util.*
import javax.annotation.Resource

@Component
class WelfareQuartz {

    @Resource
    private lateinit var appService: AppService

    /**
     * 每天0点过五分生成当天的可提取福利金
     */
    @Scheduled(cron = "0 5 0 * * ? ")
    fun welfare() {
        val totalWelfare = appService.getAllWelfare()
        val total = totalWelfare.total
        val config = totalWelfare.config
        val welfareTotal = WelfareTotal()
        welfareTotal.total = retain(total)
        welfareTotal.withdrawal = retain(total.multiply(config.maxRate).divide(BigDecimal(100)))
        appService.save(welfareTotal)
    }


}